enum<number> {
	N2 = 2 "2",
	N3 = 3 "3",
	N4 = 4 "4",
	N5 = 5 "5",
	N6 = 6 "6",
	N7 = 7 "7",
	N8 = 8 "8",
	N9 = 9 "9",
	N10 = 10 "10",
	NJ = 11 "J",
	NQ = 12 "Q",
	NK = 13 "K",
	NA = 14 "A"
}

enum<color> {
	Spade "Spade",
	Club "Club",
	Heart "Heart",
	Diamond "Diamond"
}

enum<card><number, color>

enum<player> {
	Player1 "Minglei",
	Player2 "Chenguang",
	Player3 "Bo",
	Player4 "Shu",
	Player5 "Yi"
}

container<card> deck;
container<card> tmp_deck;
container<card>[player] hand_card;

int player_input;
int[player] player_score;

event entry
{
	call start;
	call turn;
}

event start
{
	deck.shuffle;

	while (deck.size > 0) {
		hand_card[player++].add(deck.pop);
	}
}

event turn
{
	int max=0;
	int tmp_player = player;
	int win_player;
	int max_score=0;
	int i;

	while (hand_card[player].size > 0) {
		for(i=0; i < enum<player>; i++){
			do{
				output("%s, it's your turn!", player++);
				input(%d, &player_input);
			} while(!hand_card[player].contain, player_input));
			
			hand_card[player].delete(%d);
			if (player_input > max) {
				max = player_input;
				tmp_player= player;
			}
		}
		player_score[tmp_player]++;		
	}


	for (i= 0; i<4; i++) {
		if (player_score[i] > max_score) {
			win_player = i;
		}
	}
	
	output("The winner is %s", player[win_player]);
}

